//
//  ZCTabBar.m
//  百思不得姐
//
//  Created by Ning Xie on 16/8/24.
//  Copyright © 2016年 zhangchong. All rights reserved.
//

#import "ZCTabBar.h"
#import "ZCPublishViewController.h"


@interface ZCTabBar ()

@property (nonatomic, weak) UIButton *publishBtn;

@end

@implementation ZCTabBar

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        UIButton *publishBtn = [UIButton buttonWithBackgroundImage:@"tabBar_publish_icon" highlightedImage:@"tabBar_publish_click_icon"];
        [publishBtn addTarget:self action:@selector(publishBtnAction) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:publishBtn];
        self.publishBtn = publishBtn;
    }
    
    return  self;
}

-(void)publishBtnAction{
    
    ZCPublishViewController *publishVC = [[ZCPublishViewController alloc]init];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:publishVC animated:NO completion:nil];
    
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.publishBtn.center = CGPointMake(self.width * 0.5, self.height * 0.5);
    
    CGFloat width = self.width / 5;
    CGFloat height = self.height;
    CGFloat btnY = 0;
    NSInteger index = 0;
    for (UIView* button in self.subviews) {
        
        if (button == self.publishBtn || ![button isKindOfClass:[UIControl class]]) {
            continue;
        }
        CGFloat btnX = width * ((index > 1)? (index+1) : index);
        
        button.frame = CGRectMake(btnX, btnY, width, height);
        
        index ++;
    }
}
@end
